package Events;

import shared.PlayerPortfolio;
import server.ProfessionFactory;

/**
 * Wrapper/container for all events
 * @author Joel Garboden
 */
public interface Simple_Events
{
  /**
   * Generic event for receiving money
   */
  public class Simple_BalanceChange extends BaseEvent
  {
    int flat;
    double scalar;

    /**
     * Constructor
     * @param balanceChange amount of money received
     */
    public Simple_BalanceChange(int changeAmountFlat, double scalar)
    {
      this.flat = changeAmountFlat;
      this.scalar = scalar;
      
      if (changeAmountFlat != 0)
      {
        message += "Your balance changed by $" + changeAmountFlat;    
      }
      else
      {
        message += "Your balance changed by " + scalar + "%";         
      }
    }

    @Override
    public void execEvent(PlayerPortfolio portfolio)
    {
      int delta = (int)(portfolio.cashOnHand() * scalar);
      portfolio.balanceChange(delta);
    }
  }

  /**
   * Generic event for paycheck incomeChange
   */
  public class Simple_IncomeChange extends BaseEvent
  {
    int incomeChangeFlat;
    double incomeChangeFloat;

    /**
     * Constructor for generic salary increase
     */
    public Simple_IncomeChange()
    {
      this.incomeChangeFloat *= 0.05;
      message += "Raise by %" + incomeChangeFloat;
    }

    /**
     * Constructor for flat salary increase
     * @param incomeChangeFlat amount to increase by
     */
    public Simple_IncomeChange(int incomeChangeFlat)
    {
      this.incomeChangeFlat = incomeChangeFlat;
      message += "Raise " + incomeChangeFlat;
    }

    /**
     * Constructor for percentage salary increase
     * @param incomeChangeFlat amount to increase by
     */
    public Simple_IncomeChange(double incomeChangeFloat)
    {
      this.incomeChangeFloat = incomeChangeFloat;
      message += "Raise by %" + incomeChangeFloat;
    }

    @Override
    public void execEvent(PlayerPortfolio portfolio)
    {
      portfolio.incomeChange(incomeChangeFlat, incomeChangeFloat);
    }
  }

  /**
   * Generic event for credit interest rate increase
   */
  public class Simple_CardInterestRateChange extends BaseEvent
  {
    int flat;
    double scalar;

    /**
     * Constructor for flat credit card interest increase
     */
    public Simple_CardInterestRateChange(int flat, double scalar)
    {
      this.flat = flat;
      this.scalar = scalar;
      if (flat != 0)
        message += "Credit card interest changed by $" + flat;
      else
        message += "Credit card interest changed by %" + scalar;
    }

    @Override
    public void execEvent(PlayerPortfolio portfolio)
    {
      portfolio.cardInterestRateChange(flat, scalar);
    }
  }

  /**
   * Generic event for losing money
   */
  public class Simple_JobPerformanceChange extends BaseEvent
  {
    int flat;
    double scalar;

    /**
     * Constructor for flat credit card interest increase
     */
    public Simple_JobPerformanceChange(int flat, double scalar)
    {
      this.flat = flat;
      if (flat != 0)
        message += "Performance review changed by" + flat + " points";
      else
        message += "Performance review changed by" + scalar + " percent";
    }

    @Override
    public void execEvent(PlayerPortfolio portfolio)
    {
      portfolio.jobPerformanceChange(flat, scalar);
    }
  }

  /**
   * Generic event for increasing insurance deductible
   */
  public class Simple_InsuranceDeductibleChange extends BaseEvent
  {
    int flatRate;
    double scalar;

    /**
     * Constructor for flat credit card interest increase
     */
    public Simple_InsuranceDeductibleChange(int flat, double scalar)
    {
      flatRate = flat;
      this.scalar = scalar;
      if (flat != 0)
        message += "Insurance deductible just changed by $" + flat;
      else
        message += "Insurance deductible just changed by %" + scalar;
    }

    @Override
    public void execEvent(PlayerPortfolio portfolio)
    {
      portfolio.insuranceDeductibleChange(flatRate, scalar);;
    }
  }

  /**
   * Generic event for charging credit card
   */
  public class Simple_CreditChange extends BaseEvent
  {
    int flat;
    double scalar;

    /**
     * Constructor for flat credit card interest increase
     */
    public Simple_CreditChange(int flat, double scalar)
    {
      this.flat = flat;
      this.scalar = scalar;
      
      if (flat != 0)
        message += "Credit changed by $" + flat;
      else
        message += "Credit changed by %" + scalar;
    }

    @Override
    public void execEvent(PlayerPortfolio portfolio)
    {
      portfolio.chargeChange(flat, scalar);
    }
  }
}
